import { mapState } from 'vuex'
import { tracks } from '@/common/constants'
import { sendLog } from '../../api/sendLog'

export const TrackEventMixin = {
  computed: {
    ...mapState({
      userInfo: (state) => state.userInfo,
      multiLoginInfo: (state) => state.multiLoginInfo,
      channel: (state) => state.channel
    })
  },
  onShow () {
    this.sendPV()
  },
  methods: {
    async trackSubmit (event, extraParams) {
      sendLog(event, extraParams)
    },
    sendPV () {
      const pages = getCurrentPages()
      const page = pages[pages.length - 1]
      this.trackSubmit(tracks.pageView, { tag1: page.route.path })
    }
  }
}
